package com.yym.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;

import com.yym.vo.Host;

/**
 * 获取所有常量
 * 
 * @author Zuoshuai
 * 
 *         Sep 28, 2010
 */
public class ConstantUtil {
	private static List<Host> allConstantList;
	Logger log = Logger.getLogger(this.getClass());

	@SuppressWarnings("unchecked")
	public void init() {
		ApplicationContext context = ContextConf.getContext();
		allConstantList = (List<Host>) context.getBean("allConstantList");
		log.info("init successfully........");
	}

	public static List<Host> getConstantsList(String type) {
		System.out.println("执行了。。。");
		List<Host> resultList = new ArrayList<Host>();
		if (allConstantList != null && allConstantList.size() > 0) {
			for (int i = 0; i < allConstantList.size(); i++) {
				Host pojo = allConstantList.get(i);
				if (pojo.getType().equals(type)) {
					resultList.add(pojo);
				}
			}
		}
		return resultList;
	}

	public static void main(String[] args) {
//		ApplicationContext ctx = ContextConf
//				.getContextFromClassPath("applicationContext-resources.xml");
//		List<Host> a = (List<Host>) ctx.getBean("allConstantList");
//		System.out.println(a.size());

	}

}
